﻿using Newtonsoft.Json;
using Omabar.BLL;
using Omabar.Common;
using Omabar.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;

namespace Omabar.CMS.Handler
{
    /// <summary>
    /// SliderAdd 的摘要说明
    /// </summary>
    public class SliderAdd : IHttpHandler, IRequiresSessionState
    {
        public void ProcessRequest(HttpContext context)
        {
            RESP_Info info = new RESP_Info();
            try
            {
                context.Response.ContentType = "text/plain";

                string SLIDER_IMAGE = context.Request["SLIDER_IMAGE"];
                string SLIDER_URL = context.Request["SLIDER_URL"];
                string SLIDER_DES = context.Request["SLIDER_DES"];
                string SLIDER_SORT = context.Request["SLIDER_SORT"];
                string SLIDER_TYPE = context.Request["SLIDER_TYPE"];
                string SLIDER_BAK = context.Request["SLIDER_BAK"];

                SLIDER slider = new SLIDER()
                {
                    SLIDER_ID = Util.GetUID(),
                    SLIDER_IMAGE = SLIDER_IMAGE,
                    SLIDER_URL = SLIDER_URL,
                    SLIDER_DES = SLIDER_DES,
                    SLIDER_SORT = string.IsNullOrEmpty(SLIDER_SORT) ? (short)0 : short.Parse(SLIDER_SORT),
                    SLIDER_TYPE = string.IsNullOrEmpty(SLIDER_TYPE) ? (short)0 : short.Parse(SLIDER_TYPE),
                    SLIDER_BAK = SLIDER_BAK
                };

                Slider_BLL bll = new Slider_BLL();
                info = bll.Add(slider);
            }
            catch (Exception ex)
            {
                Tom.Net.Log.LogManager.Error("添加幻灯片失败", ex);
                info.Success = false;
                info.Title = "错误";
                info.Tip = "<h5><p>添加幻灯片失败</p></h5>";
                info.Url = "SliderAdd.aspx";
            }

            context.Response.Write(JsonConvert.SerializeObject(info));
        }


        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}